<?php

/**分分彩 生成开奖结果写入redis **/

/**会预加载一份下期开奖的开奖号码为空的新数据到kjjg_list 表中**/

set_time_limit(0);
error_reporting(0);
date_default_timezone_set("PRC");
require 'db_config.php';

//1.连接数据库->pdo方式
$db_pdo_link = pdo_write_read_link();  //定义为全局变量

if(!$db_pdo_link)
{
	die('pdo connection failed!');
}


//生成开奖结果


	 for($i = 0; $i<5;$i++){
		 $code .=  mt_rand(0,9); 
		 }

	  $KJ_TIME = time();
	  $qihao=$db_pdo_link->query("SELECT * FROM kkty_kjjg_list WHERE czid=62 AND  kjjg=0 AND jztime < $KJ_TIME  ORDER BY id desc   ")->fetch(PDO::FETCH_ASSOC);
     /**
	 if('' == $qihao){
		
	 }
	 */
    
	 
    $result = array(
	   "qihao" => $qihao['qihao'],
	   "czid" => '62',
	   "opencode" => $code,
	   "pentime" => date('y-m-d h:i:s',time()),
	   "opentimestamp" => time(),

	 );

	$res = json_encode($result);	
	

	
	//写入 redis
 redis_new_caipiao($res);

function redis_new_caipiao($res){
	$redis = new Redis();
	$redis->connect('10.31.74.145','6379');
	$redis->auth('Redis');
	$redis->set("ffc_kjjg","$res");
	file_put_contents('code.txt',$res,FILE_APPEND);

    echo "写入成功";
}










?>
